package com.example.rabbit.listener;

import com.example.rabbit.entity.Mail;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author:MuJiuTian
 * @Description: 此次说明 当RabbitListener用到类的注解的时候，要和RabbitHandler搭配使用
 * @Date: Created in 下午10:02 2019/8/19
 */
@Component
@RabbitListener(queues = "fanout_queue_2")
public class QueueListener {

    @RabbitHandler
    public void displayMail(Mail mail, Channel channel, Message message) throws Exception {
        System.out.println("队列监听器1号收到消息" + mail.toString());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
